package com.Calculator.view.Button.impl;

import com.Calculator.models.impl.KeysName;
import com.Calculator.models.impl.Theme;
import com.Calculator.view.Button.iMyJButton;
import javax.swing.*;
import java.awt.*;

public class KeysButton implements iMyJButton{
    private JButton[] keys;

    public KeysButton(Theme theme) {
        //获取key名字对象
        KeysName keysName = new KeysName();
        //key按钮对象数组
        this.keys = new JButton[keysName.getLength()];

        //初始化keys按钮
        for(int i = 0; i < keys.length; i++) {
            this.keys[i] = new JButton(keysName.getName()[i]);
            this.keys[i].setPreferredSize(new Dimension(10,10));
            this.keys[i].setFont(theme.getFont());
            this.keys[i].setBackground(theme.getButtonColor());
            this.keys[i].setBorder(BorderFactory.createRaisedBevelBorder());
        }
    }

    public JPanel setPanel() {
        JPanel keysPanel = new JPanel(new GridLayout(4,3,30,30));
        keysPanel.setBorder(BorderFactory.createEmptyBorder(30, 30, 30, 30));
        for (JButton key : keys) {
            keysPanel.add(key);
        }
        return keysPanel;
    }

    @Override
    public JButton[] getButton() {
        return keys;
    }

    @Override
    public void setButton(JButton[] button) {
        this.keys = button;
    }
}
